package com.muh.exchange;

import com.muh.util.RabbitMQUtil;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

public class HeadersProduct {
    private static final String EXCHANGE_NAME = "headersExchange";
    public static void main(String[] args) throws IOException, TimeoutException {
        Map<String, Object> headersParams = new HashMap<>();
        headersParams.put("one", "1");
        headersParams.put("two", "2");
        headersParams.put("three", "3");

        Connection connection = RabbitMQUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.HEADERS);//必须要是 topic 类型

        AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties().builder();
        builder.deliveryMode(MessageProperties.PERSISTENT_TEXT_PLAIN.getDeliveryMode());
        builder.priority(MessageProperties.PERSISTENT_TEXT_PLAIN.getPriority());
        builder.headers(headersParams);

        String message = "log info headers \t";
        String routingKey1 = "ourTestRoutingKey";
        channel.basicPublish(EXCHANGE_NAME, routingKey1, builder.build(), message.getBytes());

        channel.close();
        connection.close();
    }
}
